
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 08/26/2013 12:32:21
-- Generated from EDMX file: C:\Users\Benoit\Desktop\Projets Personnels\AccountManagement\Main\GestionCompte\EntityAccess\Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [MyDb];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_CategoryEntityOperationEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OperationEntitySet] DROP CONSTRAINT [FK_CategoryEntityOperationEntity];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[OperationEntitySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OperationEntitySet];
GO
IF OBJECT_ID(N'[dbo].[CategoryEntitySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CategoryEntitySet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'OperationEntitySet'
CREATE TABLE [dbo].[OperationEntitySet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [OperationDate] datetime  NOT NULL,
    [OperationAmount] float  NOT NULL,
    [OperationType] nvarchar(max)  NOT NULL,
    [CategoryEntity_Id] int  NOT NULL
);
GO

-- Creating table 'CategoryEntitySet'
CREATE TABLE [dbo].[CategoryEntitySet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [IsOneShot] bit  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'OperationEntitySet'
ALTER TABLE [dbo].[OperationEntitySet]
ADD CONSTRAINT [PK_OperationEntitySet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CategoryEntitySet'
ALTER TABLE [dbo].[CategoryEntitySet]
ADD CONSTRAINT [PK_CategoryEntitySet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [CategoryEntity_Id] in table 'OperationEntitySet'
ALTER TABLE [dbo].[OperationEntitySet]
ADD CONSTRAINT [FK_CategoryEntityOperationEntity]
    FOREIGN KEY ([CategoryEntity_Id])
    REFERENCES [dbo].[CategoryEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoryEntityOperationEntity'
CREATE INDEX [IX_FK_CategoryEntityOperationEntity]
ON [dbo].[OperationEntitySet]
    ([CategoryEntity_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------